<template>
  <div v-if="item.children">
    <template v-if="item.children.length==0">
      <el-menu-item :key="item.id" :index="item.component" @click="clickMenu()">
        <i :class="'iconfont icon-' + item.icon"></i>
        <span slot="title">{{item.name}}</span>
      </el-menu-item>
    </template>
    <el-submenu v-else :key="item.id" :index="item.id " >
      <template slot="title">
        <div  @click='itemClick(item)'>
        <i :class="'iconfont icon-' + item.icon"></i>
        <span slot="title" v-show="!isCollapse">{{item.name}}</span>
        </div>
      </template>
      <template v-for="child in item.children">
        <Menu v-if="item.children&&item.children.length>0" :key="child.id" :item="child" />
        <el-menu-item v-else :key="child.id" :index="child.component" @click="clickMenu()">
          <i :class="'iconfont icon-' + child.icon"></i>
          {{child.name}}
        </el-menu-item>
      </template>

    </el-submenu>
  </div>
</template>

<script>
export default {
  name: "Menu",
  props: ["item", "isCollapse"],
  methods: {
    clickMenu() {
      // this.$router.push({ name: this.item.label });
      this.$store.commit("ADD_TAB", this.item.label);
    },
    // 父级菜单的点击事件
    itemClick(item) {
      // console.log(item, 't');
      // console.log(item.component.includes("/") && this.$route.path != item.component)
      // 解决点击断点问题
      if (item.component.includes("/") && this.$route.path != item.component) {
        this.$router
          .push({ path: item.component })
          .catch(e => console.log(e, "ff"));
        this.$store.commit("ADD_TAB", item.label);
      }
    },
  },
  computed: {
    isActive() {
      return this.$route.path;
    },
  },
  mounted() {},
};
</script>


<style lang="less">
</style>